#coding:utf-8
import urllib2
import re
def qiubai(page):
    url="http://www.qiushibaike.com/hot/page/%d" % page
	request=urllib2.Request(url)
	request.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0')
	re_qb=re.compile(r'<div.*?class="content".*?title="(.*?)">(.*?)</div>',re.DOTALL)
	html=urllib2.urlopen(request).read()
	my_qiubai=re_qb.findall(html)
	n=len(my_qiubai)
	for i in range(n):
		for k in range(2):
			print my_qiubai[i][k].decode("utf8")
		s=raw_input(u"回车继续".encode("gb2312"))
		if s=='q':
			exit()
		print '-'*40
def for_qb():
	for page in range(int(p),280):
		print u"-"*18+u"第"+str(page)+u"页"+u"-"*18
		qiubai(page)
def if_qb():
	global p
	p=raw_input(u"输入要看的页数1~280：".encode("gb2312"))
	if p=='q':
		exit()
	elif not p.isdigit()or p=='0'or int(p)>280:
		if_qb()
	else:
		for_qb()
print u"-"*40
print u"糗事命令行版"
print u"输入'q'退出程序"
print u"-"*40
if_qb()